#include <iostream>
using namespace std;

#define MaxSize 4

struct CircleQueue{
    int data[MaxSize];
    int front,rear;
};

void Create(CircleQueue& Q)
{
    Q.front = Q.rear = -1;
}

int IsEmpty(const CircleQueue& Q)
{
    if(Q.front==-1 && Q.rear==-1) return 1;
    return 0;
}

int IsFull(const CircleQueue& Q)
{
    if((Q.rear+1)%MaxSize == Q.front) return 1;
    return 0;
}

void EnQueue(CircleQueue& Q, int x)
{
    if(IsFull(Q))
    {
        cout<<"队满 x:"<<x<<endl;
        return ;
    }

    if(IsEmpty(Q))
    {
        Q.data[0] = x;
        Q.front = MaxSize-1;
        Q.rear = 0;
    }
    else
    {
        Q.rear = (Q.rear+1)%MaxSize;
        Q.data[Q.rear] = x;
    }
}

void DeQueue(CircleQueue& Q, int& x)
{
    if(IsEmpty(Q))
    {
        cout<<"队空\n";
        return ;
    }

    if((Q.front+1)%MaxSize == Q.rear)
    {
        Q.front = (Q.front+1)%MaxSize;
        x = Q.data[Q.front];
        Q.front = Q.rear = -1;
    }
    else
    {
        Q.front = (Q.front+1)%MaxSize;
        x = Q.data[Q.front];
    }
}

void Display(const CircleQueue& Q)
{
    if(IsEmpty(Q))
    {
        cout<<"队空\n";
        return ;
    }

    int i = (Q.front+1)%MaxSize;
    int n = (MaxSize+Q.rear-Q.front)%MaxSize;
    for(int j=0; j<n; j++)
    {
        cout<<Q.data[i]<<" ";
        i = (i+1)%MaxSize;
    }
    cout<<endl;
}

int main()
{
    CircleQueue Q;
    Create(Q);
    EnQueue(Q,1);
    EnQueue(Q,2);
    EnQueue(Q,3);
    EnQueue(Q,4);
    cout<<"队列状况为 :";
    Display(Q);

    int x;
    DeQueue(Q,x);
    cout<<"乘客 "<<x<<"出队乘车\n";
    cout<<"队列状况为 :";
    Display(Q);
    return 0;
}